package com.jilujia.domain.question;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.jilujia.domain.question.repository.QuestionTagRelationRepository;
import com.jilujia.framework.domain.AbstractPoEntityManager;

@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class QuestionTagRelationManager extends
		AbstractPoEntityManager<Long, QuestionTagRelation, QuestionTagRelationRepository> {

	public void saveRelation(Long questionId, Long questionTagId) {
		QuestionTagRelation questionTagRelation = this.getRepository().findByQuestionIdAndTagId(questionId,
				questionTagId);

		// 已经存在的relation就不要增加了
		if (questionTagRelation == null) {
			questionTagRelation = new QuestionTagRelation(questionId, questionTagId);
			this.setInstance(questionTagRelation);
			this.save();
		}
	}

}
